package com.third.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.third.entity.RegisterApp;
import com.third.entity.Users;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 唐博文
 * @version 2023.1.2
 * @date 2023/10/24 20:23 星期二
 */
@Mapper
public interface UsersMapper extends BaseMapper<Users> {
    //通过RoleId找出角色名
    @Select("select role_name from role where role_id=#{id}")
    String findRoleNameByUsers(int Role_id);
    
    //通过RoleName找到RoleId
    @Select("select role_id from role where role_name=#{RoleName}")
    public int findRoleIdByRoleName(String RoleName);
    
    @Insert("insert into registerapp values(null," +
            "#{username}," +
            "#{password}," +
            "#{phone}," +
            "#{address}," +
            "#{email}," +
            "#{roleId}," +
            "'待审核')")
    public void registerApp(String username,String password,String phone,String address,String email,int roleId);
    
    @Select("select  * from registerapp")
    List<RegisterApp> getAllRegister();
    
    @Select("select  * from registerapp where username=#{username}")
    RegisterApp getRegisterApp(String username);
    
    @Delete("delete from registerapp where username=#{username}")
    void deleteRegisterApp(String username);
}
